/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qdu.servlet;

import com.qdu.entity.ActiSingUp;
import com.qdu.entity.Users;
import com.qdu.service.ActivityService;
import com.qdu.service.UserLoginSevice;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author 1964
 */
@WebServlet("/ls")
public class UserLoginServlet extends HttpServlet {

    UserLoginSevice userLoginService = new UserLoginSevice();
    ActivityService activityService = new ActivityService();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String Uid = request.getParameter("Uid");
        String Pwd = request.getParameter("pwd");
        //通过请求对象可以获取关联的会话
        HttpSession session = request.getSession();
        Users users = userLoginService.UserLogin(Uid);
        session.setAttribute("userInfo", users);
        String rigntPwd = users.getUpwd();
        
        if (rigntPwd != null) {
            if (rigntPwd.equals(Pwd)) {

                //添加一项信息到会话对象中，表示登录状态,如果会话中有isLogin这个属性，则说明用户登录了
                session.setAttribute("PageUid", Uid);
                List<ActiSingUp> signUpList = activityService.findSingUpUsers(Uid);
                request.setAttribute("SignUpList", signUpList);
                request.getRequestDispatcher("/profile.jsp").forward(request, response);
            }
            else{
                System.out.println("---------------------------密码错误--------------------------");
            }
        } else {
            System.out.println("-----------没有这个人------------------");
        }
    }

}
